/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IPlaceAttestationDao;
import com.qiyou.dao.impl.PlaceAttestationDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.PlaceAttestation;
import com.qiyou.entity.ScenicSpot;
import com.qiyou.entity.UserInfo;
import com.qiyou.util.DBUtil;

/**
 * 实地认证数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class PlaceAttestationDaoProxy implements IPlaceAttestationDao {
    private Connection conn = null;
    private IPlaceAttestationDao dao = null;

    public PlaceAttestationDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new PlaceAttestationDaoImpl(conn);
    }

    @Override
    public boolean doCreate(PlaceAttestation attestation) throws SQLException {
        if (null != attestation) {
            try {
                return dao.doCreate(attestation);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelte(long scenicSpotID, String userID)
            throws SQLException {
        if ((scenicSpotID > 0) && (null != userID)) {
            try {
                return dao.doDelte(scenicSpotID, userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public List<UserInfo> getPlaceAttestations(long scenicSpotID)
            throws SQLException {
        if (scenicSpotID > 0) {
            try {
                return dao.getPlaceAttestations(scenicSpotID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<ScenicSpot> getPlaceAttestations(String userID)
            throws SQLException {
        if (null!=userID) {
            try {
                return dao.getPlaceAttestations(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
